#!/usr/bin/env python
# encoding: utf-8
"""
    @author:水痕
    @time:2018-07-14 19:51:31
    @email:332904234@qq.com
    @version:1.0
    @fileName:author.py
    @describe:
"""
from django.shortcuts import redirect
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
from django.views import View
from book.models import AuthorModel


class AuthorView(View):
    @method_decorator(login_required)
    def post(self, request, *args, **kwargs):
        name = request.POST.get('name', None)
        if name:
            res = AuthorModel.objects.create(name=name)
            if res:
                return redirect('home')
